﻿using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Traceability.Domain.FarmingMsgs;
using Traceability.Domain.Goodss;
using Traceability.Domain.Ingredients;
using Traceability.Domain.Machinings;
using Traceability.Domain.Slaughters;
using Traceability.Services;
using Traceability.Services.GoodServices;
using Traceability.Util;

namespace Traceability.Webapi.Controllers
{
    /// <summary>
    /// 产品 API 控制器
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class ProductsController : ControllerBase
    {
        private readonly IProductService _productService;
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="productService"></param>
        public ProductsController(IProductService productService)
        {
            _productService = productService;
        }

        /// <summary>
        /// 获取产品列表
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public Task<APIResult<PageIng<ProductDto>>> GetProducts(int PageIndex, int PageSize)
        {

            return _productService.GetProducts(PageIndex, PageSize);
        }
        /// <summary>
        /// 新增产品
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        [HttpPost]
        public Task<APIResult<int>> ProductInsert(ProductInsertDto entity)
        {
            return _productService.ProductInsert(entity);
        }

        /// <summary>
        /// 获取商品列表
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public async Task<APIResult<List<Goods>>> GetGoods()
        {
            return await _productService.GetGoods();
        }
        /// <summary>
        /// 更新产品
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpDelete]
        public async Task<APIResult<int>> ProductUpdate(int id)
        {
            return await _productService.ProductUpdate(id);
        }
        /// <summary>
        /// 修改产品
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        [HttpPut]
        public Task<APIResult<int>> ProductUpdate(ProductUpdateDto entity)
        {
            return _productService.ProductUpdate(entity);
        }
        /// <summary>
        /// 查询信息
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpGet]
        public Task<APIResult<List<ProductDto>>> GetProductAndGoodsName(int id)
        {
            return _productService.GetProductAndGoodsName(id);
        }
        /// <summary>
        /// 新增养殖信息
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<APIResult<int>> CultivationInsert(CultivationInsertDto entity)
        {
            return await _productService.CultivationInsert(entity);
        }

        /// <summary>
        /// 更新养殖信息
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        [HttpPut]
        public async Task<APIResult<int>> CultivationUpdate(CultivationUpdateDto entity)
        {
            return await _productService.CultivationUpdate(entity);
        }

        /// <summary>
        ///  免疫信息查询所有
        /// </summary>
        /// <returns></returns>
        [HttpGet]
       public Task<APIResult<List<Immunity>>> GetImmunity()
        {
            return _productService.GetImmunity();
        }

        /// <summary>
        /// 根据商品编号查询养殖信息
        /// </summary>
        /// <param name="productCode"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<APIResult<List<Cultivation>>> GetCultivationByProductCode(string productCode)
        {
            
            return await _productService.GetCultivationByProductCode(productCode);
        }

        /// <summary>
        /// 添加免疫信息
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<APIResult<int>> ImmunityInsert(ImmunityInsertDto entity)
        {
            return await _productService.ImmunityInsert(entity);
        }
        /// <summary>
        /// 根据商品编号查询企业信息
        /// </summary>
        /// <param name="productCode"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<APIResult<List<Enterprise>>> GetEnterpriseByProductCode(string productCode)
        {
            return await _productService.GetEnterpriseByProductCode(productCode);
        }
        /// <summary>
        /// 根据商品编号查询屠宰信息
        /// </summary>
        /// <param name="productCode"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<APIResult<List<Slaughter>>> GetSlaughterByProductCode(string productCode)
        {
            return await _productService.GetSlaughterByProductCode(productCode);
        }

        /// <summary>
        /// 屠宰信息添加
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<APIResult<int>> SlaughterInsert(SlaughterInsertDto entity)
        {
            return await _productService.SlaughterInsert(entity);
        }
        /// <summary>
        /// 企业信息添加
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<APIResult<int>> EnterpriseInsert(EnterpriseInsertDto entity)
        {
            return await _productService.EnterpriseInsert(entity);
        }

        /// <summary>
        /// 深加工企业信息添加
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<APIResult<int>> MachiningEnterpriseInsert(MachiningEnterpriseInsertDto entity)
        {
                return await _productService.MachiningEnterpriseInsert(entity);
        }

        /// <summary>
        /// 根据商品编号查询深加工
        /// </summary>
        /// <param name="productCode"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<APIResult<List<MachiningEnterprise>>> GetMachiningEnterpriseByProductCode(string productCode)
        {
            return await _productService.GetMachiningEnterpriseByProductCode(productCode);
        }

        /// <summary>
        /// 根据商品编号查询原料信息
        /// </summary>
        /// <param name="productCode"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<APIResult<List<Material>>> GetMaterialByProductCode(string productCode)
        {
            return await _productService.GetMaterialByProductCode(productCode);
        }

        /// <summary>
        /// 根据商品编号查询辅料
        /// </summary>
        /// <param name="productCode"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<APIResult<List<Accessories>>> GetAccessoryByProductCode(string productCode)
        {
            return await _productService.GetAccessoryByProductCode(productCode);
        }
        /// <summary>
        /// 根据商品编号查询添加剂信息
        /// </summary>
        /// <param name="productCode"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<APIResult<List<Additive>>> GetAdditiveByProductCode(string productCode)
        {
            return await _productService.GetAdditiveByProductCode(productCode);
        }

        /// <summary>
        /// 根据商品编号查询包材信息
        /// </summary>
        /// <param name="productCode"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<APIResult<List<PackeMaterial>>> GetPackingByProductCode(string productCode)
        {
            return await _productService.GetPackingByProductCode(productCode);
        }
    }
}
